<template>
	<div class="addProject business-workAdd">
		<div class="addForm zll-form">
			<el-form :model="addForm" ref="addForm" class="demo-ruleForm">
				<el-row :gutter="40">
					<el-col :span="12">
						<el-form-item class="formList" prop="data1" label="出库时间">
							<el-input clearable class="input_right" placeholder="请输入出库时间" v-model="time"
									  disabled></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item class="formList" prop="data2" label="出库人：">
							<el-input clearable class="input_right" placeholder="请输入子品类" v-model="user.userName"
									  disabled></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<div class="tableList">
					<table>
						<tr>
							<th>废料类型</th>
							<th>出库重量（kg）</th>
							<th>是否分拣</th>
						</tr>
						<tr v-for="(item,index) in tableList" :key="index">
							<td>{{item.abandonTypeCn}}</td>
							<td>
								<el-input  v-model="item.outWeight"  @input="item.outWeight=item.outWeight.replace(/[^0-9\.]/g,'')"  clearable class="text_center" placeholder=""></el-input>
							</td>
							<td>
								<p>
									<el-select clearable v-model="item.fenlian" placeholder="是否分拣" :disabled="item.disabled">
										<el-option label="否" value="0"></el-option>
										<el-option label="是" value="1"></el-option>
									</el-select>
							    </p>
							</td>
						</tr>
					</table>
				</div>
			</el-form>
		</div>
	</div>
</template>
<script>

	import {getStore} from "@/plugins/localStore";
	import {formatDate} from "@/plugins/formatDate";

	export default {
		props: ['editData', 'type'],
		data() {
			return {
				addForm: {

				},
				time:'',
				rules: {

				},
				tableList: [],
				user:{},
				count:0,
			}
		},
		methods: {
			submitForm(val, type) {
				let self = this;
				let params = [];
				for(let data of self.tableList){
					if(data.outWeight&&data.fenlian){
						params.push(data);
					}
				}
				if(params.length == 0){
					self.$message.warning('至少添加一个！');
					return;
				}
				if (self.count == 0) {
					self.$http({
						url: '/jinl/abandonHandle/addBatchAbandonMaterialHandles',
						method: "post",
						data: JSON.stringify(params),
						dataType: 'json',
						contentType: "application/json",
					}).then(resp => {
						if (resp.success) {
							self.$notify({title: '提示', message: "操作成功！", type: 'success'});
							self.count--;
							self.$emit("refreshPage");
							return;
						}
						self.$notify({title: '提示', message: resp.message, type: 'error'});
						self.count--;
					});
					self.count++;
				}
			},
		},

		watch:{
			editData(val) {
				console.log('======editData=========')
				console.log(val)
				this.user = getStore();
				this.count = 0;
				this.time =formatDate(new Date(), 'yyyy-MM-dd');
				let type1 = {abandonType:'1',abandonTypeCn:'料头',outWeight:'',fenlian:'',outUserName:this.user.userName};
				let type2 = {abandonType:'2',abandonTypeCn:'可回收',outWeight:'',fenlian:'0',disabled:true,outUserName:this.user.userName};
				let type3 = {abandonType:'3',abandonTypeCn:'不可回收',outWeight:'',fenlian:'0',disabled:true,outUserName:this.user.userName};
				let type4 = {abandonType:'4',abandonTypeCn:'彩膜',outWeight:'',fenlian:'',outUserName:this.user.userName};
				this.tableList.push(type1);
				this.tableList.push(type2);
				this.tableList.push(type3);
				this.tableList.push(type4);
			},
		},

		mounted() {

		},
		components: {},
	}
</script>
<style lang="scss" scoped>
	@import "@/style/dialog.scss";
</style>